package com.authine.cloudpivot.ext.quartz;


import com.authine.cloudpivot.ext.quartz.task.UnifiedJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import java.lang.reflect.Method;
import java.lang.reflect.Modifier;

@Component
@Slf4j
public class JobManger implements CommandLineRunner {


    @Autowired
    private UnifiedJob unifiedJob;


    @Override
    public void run(final String... args) throws Exception {

        try {
            log.info("\n============开始创建 统一定时任务管理============");
            Method[] methods = unifiedJob.getClass().getDeclaredMethods();
            for (Method method : methods) {
                if (Modifier.isPublic(method.getModifiers())){
                    method.invoke(unifiedJob);
                }
            }
            log.info("\n============完成创建 统一定时任务管理============");
        }catch (Exception e){
            log.error("创建定时异常:{}", e);
        }


    }



}
